<template>
  <div>
     <div>
        <label>姓名:</label>
        <input type="text" v-model="user.username">
     </div>
     <div>
        <label>密码:</label>
        <input type="password" v-model="user.password">
     </div>
     <div>
        <button @click="login">登录</button>
     </div>
  </div>
</template>

<script>
export default {
   data(){
      return{
         user:{
            username:"",
            password:""
         }
      }
   },
   methods:{
      async login(){
         const result=await this.$api.users.loginApi(this.user)
         if(result.code){
            this.$message.success('登录成功')
            //将token存储到localStorage中
            localStorage.setItem('token',result.token)
            //路由跳转
            this.$router.push('/mine')
         }
      }
   }
}
</script>

<style>

</style>